package com.example.bandlock;

import android.content.Context;
import android.content.res.TypedArray;
import android.preference.SwitchPreference;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Switch;
import android.widget.TextView;

public class LockSwitchPreference extends SwitchPreference {
	private static final String TAG = "langxw";

	private Switch mSwitch;
	private boolean mChecked = false;
	private Context mContext;
	String title = null;
	String summary = null;
	String tipstring = null;

	public LockSwitchPreference(Context context, AttributeSet attrs,
			int defStyle) {
		super(context, attrs, defStyle);
		mContext = context;
//		TypedArray ta = context.obtainStyledAttributes(attrs,
//				R.styleable.LockSwitchPreference);
//		title = ta.getString(R.styleable.LockSwitchPreference_android_title);
//		summary = ta.getString(R.styleable.LockSwitchPreference_android_summary);
//		tipstring = ta.getString(R.styleable.LockSwitchPreference_tipstring);
//		ta.recycle();
	}

	public LockSwitchPreference(Context context, AttributeSet attrs) {
		super(context, attrs);
		mContext = context;
		setWidgetLayoutResource(R.layout.smart_gesture_switch);
	}

	public LockSwitchPreference(Context context) {
		super(context);
		mContext = context;
		setWidgetLayoutResource(R.layout.smart_gesture_switch);
	}

	@Override
	protected void onBindView(View view) {
		mSwitch = (Switch) view.findViewById(R.id.prefrence_switch_id);

		view.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Log.i(TAG, "click, title: " + title + ", summary: " + summary + ", tipstring: " + tipstring);
			}
		});
		if (mSwitch != null) {
			mSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

				@Override
				public void onCheckedChanged(CompoundButton button,
						boolean checked) {
					mChecked = checked;
					Log.i(TAG, "onCheckedChanged, checked : " + checked);
				}
			});
		}
		TextView pTitleView = (TextView) view.findViewById(R.id.title);
		pTitleView.setText(title);
		TextView pTipView = (TextView) view.findViewById(R.id.summary);
		pTipView.setText(summary);
		super.onBindView(view);
	}

}